#include "TLKSetObjectVel.h"
#include "ObjUsefulFunctions.h"
#include "Game.h"
#include "TimeLineKeyFactory.h"
#include <assert.h>

TLKSetObjectVel::TLKSetObjectVel()
{
	m_ObjID = 0;
}

bool TLKSetObjectVel::Load(File* f)
{
	if(!f->GetInteger(&m_ObjID))
	{
		f->ReportFileError(std::string("Cannot find Object Id"));
		return false;
	}
	
	std::string NewVel;
	if(!f->GetString(&NewVel))
	{
		f->ReportFileError(std::string("Cannot Find New Velocity"));
		return false;
	}

	Strings strs = Split(NewVel, '/');

	assert(strs.size() == 3);
	
	m_NewVel.m_x = ToFloat(strs[0]);
	m_NewVel.m_y = ToFloat(strs[1]);
	m_NewVel.m_z = ToFloat(strs[2]);
}

void TLKSetObjectVel::Exec()
{
	Vec3f* CurrentVel = TheGame::Instance()->GetObject(m_ObjID)->GetVel();

	*CurrentVel = m_NewVel;
}

TimelineKey* CreateTLKSetObjectVel()
{
	return new TLKSetObjectVel;
}

const char* TLKSetObjectVel::GetTypeName() const
{
	return "TLKSetObjectVel";
}

static bool l = TheTLKFactory::Instance()->AddToMap("TLKSetObjectVel", CreateTLKSetObjectVel);